#ifndef SDVGLWIDGET_H
#define SDVGLWIDGET_H

#include <QOpenGLWidget>
#include <QOpenGLFunctions_3_3_Compatibility>

#include "camera.h"
#include "shader.h"
#include "model.h"

struct draw_type {
    int type; // 0: none; 1: point; 2: line; 3: cover
};

struct animation_state {
    int animation_timer_id;
    int isAnimating;
};

struct texture_state {
    int texEnable;
    QVector3D orgColor;
};

struct move_type {
    int move_type; // 0: none; 1: fps camera; 2: rotation
    float xoffset; // 1
    float yoffset; // 1
    float r_xoffset; // 2
    float r_yoffset; // 2
    float lastX;
    float lastY;
    bool firstMouse;
};

struct light_type {
    int l_type; // 0: no light; 1: point-light; 2: directional-light; 3: spot-light
};

class sdvGLWidget : public QOpenGLWidget, protected QOpenGLFunctions_3_3_Compatibility
{
public:
    sdvGLWidget(QWidget *parent);
    ~sdvGLWidget();

    void loadModelClarkBoxcube();
    void loadModelClarkCube();
    void loadModelLoopCone();
    void loadModeLoopZ();

    void subdivision();
    void original();

    void keyPressEvent(QKeyEvent *event);

    void initFpsCamera();

protected:
    void initializeGL();
    void paintGL();
    void resizeGL(int w,int h);

    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void wheelEvent(QWheelEvent *event);
    void timerEvent(QTimerEvent *event);

private:
    QOpenGLFunctions * m_func;
    Camera camera;
    Shader* ourShader;
    Model* ourModel;
    Model* ourModel1, *ourModel2, *ourModel3, *ourModel4;

    QMatrix4x4 model;
    QMatrix4x4 projection;
    QMatrix4x4 view;

    // lamp
    Shader* lampShader;
    QVector3D lightPos;
    unsigned int lightVAO, lightVBO;
};

#endif // SDVGLWIDGET_H
